package factory.simplefactory;

/**
 * @author wcj
 * @Date 2021/6/20 21:55
 * @Version 1.0
 */
public class Client {

    /**
     * 简单工厂模式：主要目的是为了实现对于创建对象操作的封装和隐藏，客户端不需要去关心对象的创建
     * 简单工厂模式的优点：实现了对象创建操作的封装和隐藏
     * 简单工厂模式的缺点：不满足开闭原则，即满足了对扩展开放，但是也允许了扩展的开放
     * 复杂度方面：每次新增一个操作，都需要新增一个实体类和修改工厂中的分支语句，修改的内容不算多
     *
     * @param args
     */
    public static void main(String[] args) {
        OperationFactory factory = new OperationFactory();

        Operation operationAdd = factory.getResult("+");
        System.out.println(operationAdd.operation(5L, 6L));

        Operation operationSub = factory.getResult("-");
        System.out.println(operationSub.operation(8L, 2L));

        Operation operationMul = factory.getResult("*");
        System.out.println(operationMul.operation(8L, 2L));

        Operation operationDiv = factory.getResult("/");
        System.out.println(operationDiv.operation(8L, 2L));
        System.out.println(operationDiv.operation(8L, 0L));

        Operation operationPer = factory.getResult("%");
        System.out.println(operationPer.operation(5L, 2L));
    }
}
